/**
 * 
 */
package org.osami.phidget.disco;

import java.util.Properties;

import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.MissingHandlerException;
import org.apache.felix.ipojo.UnacceptableConfiguration;

import com.phidgets.InterfaceKitPhidget;
import com.phidgets.PhidgetException;
import com.phidgets.event.AttachEvent;
import com.phidgets.event.AttachListener;
import com.phidgets.event.DetachEvent;
import com.phidgets.event.DetachListener;
import com.phidgets.event.ErrorEvent;
import com.phidgets.event.ErrorListener;

/**
 * @author tai
 * 
 */
public class TestPhidget {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestPhidget.init();
	}

	public static void init() {
		try {
			final InterfaceKitPhidget m_phidget = new InterfaceKitPhidget();
			m_phidget.addAttachListener(new AttachListener() {

				public void attached(AttachEvent arg0) {
					System.out.println("[Disco]AttachEvent received.");
					// get params
//					try {
//						int l_id = arg0.getSource().getSerialNumber();
//
//						System.out.println("[Disco]Instance created.");
//					} catch (PhidgetException e) {
//						// TODO Auto-generated catch block
//						e.printStackTrace();
//
//					} catch (Throwable t) {
//						t.printStackTrace();
//					}
					// Call factory for instance creation

				}

			});

			m_phidget.addDetachListener(new DetachListener() {

				public void detached(DetachEvent arg0) {
					System.out.println("[Disco]DetachEvent received");
				}
			});

			m_phidget.addErrorListener(new ErrorListener() {
				
				public void error(ErrorEvent arg0) {
					// TODO Auto-generated method stub
					System.out.println("Error received");
					
				}
			});
				
			m_phidget.openAny();

			while (true) {
				Thread.sleep(500);
			}

			// System.out.println("waiting for attachment...");
			// while (true){
			// while (!m_phidget.isAttached()){
			// m_phidget.openAny();
			// System.out.println("Inner loopLet's open it!");
			// Thread.sleep(500);
			// }
			// Thread.sleep(500);
			// }
			// Thread.sleep(500);
			// }

		} catch (PhidgetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
